<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分类</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">

    <style>
        .layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
            height: 34px;
            line-height: 34px;
            padding: 0 8px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div>
            <table id="goodstype-table" class="layui-table" lay-filter="goodstype-table"></table>
        </div>
    </div>
</div>
<!-- 操作列 -->
<!-- <script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script> -->
<script type="text/html" id="toolButton">
    <div class="layui-btn-container">
        <div class="layui-btn-group" >
            {{#  if(HavePermission('goodstype-add')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="add" lay-event="add">新增<i class="layui-icon"></i></button>
            {{#  }  }}
            {{#  if(HavePermission('goodstype-update')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="update" lay-event="update">修改<i class="layui-icon"></i></button>
            {{#  }  }}
            {{#  if(HavePermission('goodstype-delete')){ }}
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" id="delete" lay-event="delete">删除<i class="layui-icon"></i></button>
            {{#  }  }}
        </div>
    </div>
  </script>
  
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8">
</script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/js/custorm/init.js"></script>
<script>
    layui.use(['table', 'treetable'], function () {
        var $ = layui.jquery,
        treetable=layui.treetable,
         table = layui.table;
        initTable();
        // 渲染表格
       function renderTable(d){
            layer.load(4);
        treetable.render({
            treeColIndex: 1,
            treeSpid: 0,
            treeIdName: 'id',
            treePidName: 'parentid',
            elem: '#goodstype-table',
            toolbar: '#toolButton',
            data:d,
            page: false,
            cols: [[
                 {type: 'checkbox', fixed: 'left'},
                {field: 'name', minWidth: 80, title: '名称'},
                {field: 'level', minWidth: 80, align: 'center', title: '级别'},
                {
                    field: 'status', width: 80, align: 'center', templet: function (d) {
                        if (d.status == true) {
                            return '<span class="layui-badge layui-bg-gray ">有效</span>';
                        }
                        else  {
                            return '<span class="layui-badge layui-bg-gray">无效</span>';
                        }
                    }, title: '状态'
                },
                {field: 'sort', minWidth: 80, title: '排序',sort:true},
                {field: 'createtime', minWidth: 80, align: 'center', title: '创建时间'},
                {field: 'updatetime', minWidth: 80, align: 'center', title: '修改时间'},
                {field: 'createuser', minWidth: 80, align: 'center', title: '创建人'},
                {field: 'updateuser', minWidth: 80, align: 'center', title: '修改人'},
            ]],
            done: function () {
                layer.closeAll('loading');
            }
        });
        }
      function initTable(){
        AxajGet('../api/shop/GetAllGoodsType','../../login.html',renderTable);
      }
          //头工具栏事件
        table.on('toolbar(goodstype-table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
            case 'add':
                window.location.href="goodstype/add.html";
            break;
            case 'update':
                var data = checkStatus.data;
                if(data.length!=1){
                    layer.msg("请选择一条数据");
                    return;
                }
                window.location.href="goodstype/edit.html?id="+data[0].id;
            break;
            case 'delete':
                var data = checkStatus.data;
                if(data.length!=1){
                    layer.msg("请选择一条数据");
                    return;
                }
                AxajPost('../api/shop/DeleteGoodsType',data[0],'删除成功','../../login.html',initTable);
                
            break;
            
            //自定义头工具栏右侧图标 - 提示
            case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
            break;
            };
        });

    });
</script>
</body>
</html>